/**
 * 
 */
package com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.useroption;

import com.alstudio.module.xmpp.protocol.xmpp.data.ALXmppData;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALXmppDomainConfig;
import com.alstudio.module.xmpp.protocol.xmpp.packact.IQNameSpace;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.AlXmlTag;
import com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate;
import com.alstudio.utils.encode.ALDES;

/**
 * 更改密码
 * 
 * @author alonso lee
 * 
 */
public class ChangePwdIQCreator extends BaseIQTemplate {

	private String oripassword, newpassword;

	/**
	 * 
	 */
	public ChangePwdIQCreator(String oripassword, String newpassword,
			String domain) {
		// TODO Auto-generated constructor stub
		this.domain = domain;
		this.oripassword = oripassword;
		this.newpassword = newpassword;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.util.xmlcreator.iq.BaseIQTemplate
	 * #getIQXml()
	 */
	@Override
	public String getIQXml() {
		to = ALXmppDomainConfig.getALXmppDomainConfig().getDomainByNameSpace(
				IQNameSpace.NS_CHANGE_PWD);
		mALIQCreator.setTo(to + domain);
		mALIQCreator.setNs(IQNameSpace.NS_CHANGE_PWD);
		mALIQCreator.setType(IQ_TYPE_SET);

		// 旧密码
		AlXmlTag tag = new AlXmlTag("oripassword");
		try {
			tag.setText(ALDES.encryptDES(oripassword, ALXmppData.DES_KEY));
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		tagList.add(tag);
		mALIQCreator.setTagList(tagList);

		// 新密码
		tag = new AlXmlTag("password");
		try {
			tag.setText(ALDES.encryptDES(newpassword, ALXmppData.DES_KEY));
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		tagList.add(tag);
		mALIQCreator.setTagList(tagList);

		String xml = "";
		try {
			xml = mALIQCreator.getXml();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return xml;
	}

}
